package com.cgbl.cg.vm.home

import android.app.Application
import androidx.databinding.ObservableField
import api.ProjectServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.model.CourseInfoFileBean
import com.robot.base.model.ProjectBean
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent
import me.goldze.mvvmhabit.http.BaseResponse

class CaseDetailsViewModel(application: Application) : GLBaseViewModel(application) {
    val title = ObservableField("")
    val budget = ObservableField("")
    val infoComment = ObservableField("")
    val cycle = ObservableField("")

    val uc = UiChangeEvent()

    class UiChangeEvent {
        val labelDataEvent = SingleLiveEvent<String>()
        val imgDataEvent = SingleLiveEvent<List<CourseInfoFileBean>>()
    }

    fun getCase(id: String) {
        ProjectServiceFactory.getCase(id)
            .subscribe(object : AbstractViewModelSubscriber<BaseResponse<ProjectBean>>(this) {
                override fun onNext(t: BaseResponse<ProjectBean>) {
                    title.set(t.data.title)
                    budget.set(t.data.budget)
                    infoComment.set(t.data.infoComment)
                    cycle.set(t.data.cycle)
                    uc.labelDataEvent.postValue(t.data.itemLabel)
                    uc.imgDataEvent.postValue(t.data.itemCaseFileDOS)
                }
            })
    }
}